<template>
  <el-dialog
    title="开发商列表"
    :visible.sync="dialogFormVisible"
    width="1000px"
    append-to-body
    @close="() => (dialogFormVisible = false)"
  >
    <el-card shadow="hover">
      <vab-query-form>
        <el-form
          :model="queryForm.queryBean"
          :inline="true"
          @submit.native.prevent
        >
          <el-form-item>
            <el-input
              v-model.trim="queryForm.queryBean.phone"
              placeholder="手机号码"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.queryBean.userName"
              placeholder="用户名"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button
              icon="el-icon-search"
              type="primary"
              native-type="submit"
              @click="handleQuery"
            >
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form>
      <el-table
        v-loading="listLoading"
        :data="list"
        :element-loading-text="elementLoadingText"
        :height="height"
      >
        <el-table-column
          show-overflow-tooltip
          prop="userName"
          label="用户名称"
          width="100"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          label="手机号码"
          prop="phone"
          width="120"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          label="地产名称"
          prop="attributes.developerInfo.businessEstateName"
        ></el-table-column>
        <el-table-column show-overflow-tooltip label="操作" width="200">
          <template #default="{ row }">
            <el-button
              type="primary"
              icon="el-icon-set-up"
              @click="handleSet(row)"
            ></el-button>
            <!-- <el-button type="text" >删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :background="background"
        :current-page="queryForm.pageNum"
        :layout="layout"
        :page-size="queryForm.pageSize"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      ></el-pagination>
    </el-card>
  </el-dialog>
</template>

<script>
  import { getUserList } from '@/api/user'
  export default {
    name: 'DevelopDialog',
    data() {
      return {
        dialogFormVisible: false,
        imgShow: true,
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        background: true,
        elementLoadingText: '正在加载...',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          queryBean: {
            roleId: '3',
          },
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      this.fetchData()
    },
    mounted() {},
    methods: {
      handleSet(row) {
        this.$emit('click', row)
        this.dialogFormVisible = false
      },
      showEdit() {
        this.dialogFormVisible = true
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      handleQuery() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        console.log(this.queryForm)
        const { data } = await getUserList(this.queryForm)
        const { body } = data
        console.log(body.data)
        this.list = body.data
        this.total = body.totalSize
        this.$baseNotify('开发商数据获取完毕！', '成功', 'success', 'top-right')
        setTimeout(() => {
          this.listLoading = false
        }, 500)
      },
    },
  }
</script>
